﻿@using Newtouch.Infrastructure
@{
    ViewBag.Title = "SettConfirmForm";
    Layout = "~/Views/Shared/_Form.cshtml";
    //住院结算可以用预交金
    var withYjj = SysConfigReader.Bool("InpatientSettWithAdvanceAccount");
    //
    var relatedFPH = SysConfigReader.Bool("Inpatient_SettPage_RelatedFPH");
    //有与CPOE互通接口
    var interfaceWithCPOE = SysConfigReader.Bool("HOSP_INTERFACE_WITH_CPOE", false).Value;
    //是否移动支付
    var needPay = SysConfigReader.Bool("Inpatient_Sett_NeedPay") ?? false;
    //默认支付方式
    var defaultPayMethod = SysConfigReader.String("Sett_PayMethod_Inp_Default");
    //是否允许多种支付
    var sfyxdzzf = SysConfigReader.Bool("Intpatient_Sett_Open_Dzzf", false);
    //医保所属地，区分系统将执行何处医保逻辑
    var medicalInsurance = SysConfigReader.String("Inpatient_MedicalInsurance");
    //结算金额分币误差控制
    var SettPayBalance = SysConfigReader.Bool("SettPayBalance", false);
    //默认是否退余额
    var refundyjj = SysConfigReader.String("Sett_Inpatient_RefundAccount");
    var opr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
}

<!--贵安医保展示-->
<div id="divGuiAnYbFee" class="panel panel-default" style="display:none;margin-top:10px;margin-left:10px;margin-right: 10px;">
    <div class="panel-heading navb-bg" style="height:13px;">
        费用信息
    </div>
    <div style="height:auto;">
        <table class="form">
            <tr>
                <th class="formTitle">费用总额：</th>
                <td class="formValue">￥<label id="his_hisfyze">0.00</label></td>
                <th class="formTitle">现金支付：</th>
                <td class="formValue">￥<label id="calc_xjzf">0.00</label></td>
                <th class="formTitle">账户支付：</th>
                <td class="formValue">￥<label id="prm_yka065">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">基本医疗报销：</th>
                <td class="formValue">￥<label id="prm_yka248">0.00</label></td>
                <th class="formTitle">大病医疗报销：</th>
                <td class="formValue">￥<label id="prm_yka062">0.00</label></td>
                <th class="formTitle">公务员补报销：</th>
                <td class="formValue">￥<label id="prm_yke030">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">伤残人员医疗保障：</th>
                <td class="formValue">￥<label id="prm_ake032">0.00</label></td>
                <th class="formTitle">民政补助：</th>
                <td class="formValue">￥<label id="prm_ake181">0.00</label></td>
                <th class="formTitle">其他基金支付：</th>
                <td class="formValue">￥<label id="prm_ake173">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">本次起付线：</th>
                <td class="formValue">￥<label id="prm_yka058">0.00</label></td>
            </tr>
        </table>
    </div>
</div>

<!--医保展示-->
<div id="divQHDYbFee" class="panel panel-default" style="display:none;margin-top:10px;margin-left:10px;margin-right: 10px;">
    <div class="panel-heading navb-bg" style="height:13px;">
        费用信息
    </div>
    <div style="height:auto;">
        <table class="form">
            <tr>
                <th class="formTitle">费用总额：</th>
                <td class="formValue">￥<label id="cq_fyze">0.00</label></td>
                <th class="formTitle">现金支付合计：</th>
                <td class="formValue">￥<label id="cq_xjzf">0.00</label></td>
                <th class="formTitle">非医保现金计费：</th>
                <td class="formValue">￥<label id="zf_xjzf">0.00</label></td>

            </tr>
            <tr>
                <th class="formTitle">医保现金计费：</th>
                <td class="formValue">￥<label id="yb_xjzf">0.00</label></td>
                <th class="formTitle">统筹支付：</th>
                <td class="formValue">￥<label id="cq_tczf">0.00</label></td>
                <th class="formTitle">公务员补助：</th>
                <td class="formValue">￥<label id="cq_gwybz">0.00</label></td>


            </tr>
            <tr>
                <th class="formTitle">账户支付：</th>
                <td class="formValue">￥<label id="cq_zhzf">0.00</label></td>
                <th class="formTitle">医院负担金额：</th>
                <td class="formValue">￥<label id="dbzddyljgdz">0.00</label></td>

                <th class="formTitle">大额理赔支付：</th>
                <td class="formValue">￥<label id="cq_delp">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">企业医疗保险支出：</th>
                <td class="formValue">￥<label id="cq_qybxzc">0.00</label></td>
                <th class="formTitle">居民大病支出：</th>
                <td class="formValue">￥<label id="cq_jmdbzc">0.00</label></td>
                <th class="formTitle">医疗救助基金支出：</th>
                <td class="formValue">￥<label id="cq_mzbz">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">账户共济支付：</th>
                <td class="formValue">￥<label id="cq_zhgjzf">0.00</label></td>
                <th class="formTitle">其他：</th>
                <td class="formValue">￥<label id="cq_qt">0.00</label></td>
            </tr>
        </table>
    </div>
</div>
<!-- 上海医保展示 -->
<div id="divShYbV5Fee" class="panel panel-default" style="display:none; margin-top:10px;margin-left:10px;margin-right: 10px;">
    <div class="panel-heading navb-bg" style="height:13px;">
        费用信息
    </div>
    <div style="height:auto;">
        <table class="form">
            <tr>
                <th class="formTitle">总费用：</th><!--使用-->
                <td class="formValue">￥<label id="ZFY">0.00</label></td>
                <th class="formTitle">现金支付合计：</th>
                <td class="formValue">￥<label id="XJZF">0.00</label></td>
                <th class="formTitle">医保现金计费：</th><!--使用-->
                <td class="formValue">￥<label id="YBJF">0.00</label></td>

            </tr>
            <tr>
                <th class="formTitle">非医保现金计费：</th><!--无医保代码金额-->
                <td class="formValue">￥<label id="ZFJF">0.00</label></td>
                <th class="formTitle">当年帐户支付数：</th>
                <td class="formValue">￥<label id="curaccountpay">0.00</label></td>
                <th class="formTitle">历年帐户支付数：</th>
                <td class="formValue">￥<label id="hisaccountpay">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">自负段现金支付数：</th>
                <td class="formValue">￥<label id="zfdxjzfs">0.00</label></td>
                <th class="formTitle">自负段历年支付数：</th>
                <td class="formValue">￥<label id="zfdlnzhzfs">0.00</label></td>

                <th class="formTitle">统筹段帐户支付数：</th>
                <td class="formValue">￥<label id="tcdzhzfs">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">统筹段现金支付数：</th>
                <td class="formValue">￥<label id="tcdxjzfs">0.00</label></td>
                <th class="formTitle">统筹支付数：</th>
                <td class="formValue">￥<label id="tczfs">0.00</label></td>
                <th class="formTitle">附加段帐户支付数：</th>
                <td class="formValue">￥<label id="fjdzhzfs">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">附加段现金支付数：</th>
                <td class="formValue">￥<label id="fjdxjzfs">0.00</label></td>
                <th class="formTitle">附加支付数：</th>
                <td class="formValue">￥<label id="fjzfs">0.00</label></td>
                <th class="formTitle">当年帐户余额：</th>
                <td class="formValue">￥<label id="curaccountamt">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">历年帐户余额：</th>
                <td class="formValue">￥<label id="hisaccountamt">0.00</label></td>
                <th class="formTitle">附加段共济账户支付：</th>
                <td class="formValue">￥<label id="fjdgjzhzfs">0.00</label></td>
                <th class="formTitle">起付段共济账户支付：</th>
                <td class="formValue">￥<label id="qfdgjzhzfs">0.00</label></td>
                @*
                    <th class="formTitle">医保结算范围总额：</th>
                    <td class="formValue">￥<label id="ybjsfwfyze">0.00</label></td>
                    <th class="formTitle">非医保结算范围总额：</th>
                    <td class="formValue">￥<label id="fybjsfwfyze">0.00</label></td>*@

            </tr>
            <tr>
                <th class="formTitle">统筹段共济账户支付：</th>
                <td class="formValue">￥<label id="tcdgjzhzfs">0.00</label></td>
                <th class="formTitle">预结算账户余额：</th>
                <td class="formValue">￥<label id="yjs">0.00</label></td>
                @*
                    <th class="formTitle">自费段共济账户支付：</th>
                    <td class="formValue">￥<label id="zfdgjzhzfs">0.00</label></td>*@

            </tr>
        </table>
    </div>
</div>

<div class="panel panel-default" style="margin-top:10px;margin-left:10px;margin-right: 10px;">
    <div class="panel-heading navb-bg" style="height:13px;">
        支付信息
    </div>
    <div style="height:auto;">
        <table class="form" id="tablezf">
            <tr>
                <th class="formTitle">住院号：</th>
                <td class="formValue">
                    <label id="lblZyh"></label>
                </td>
                @if (relatedFPH == true)
                {
                    <th class="formTitle"><span style="color:red">*</span>发票号：</th>
                    <td class="formValue">
                        <label id="txtfph"></label>
                        <div style="position:absolute;top:5px;right:20px;">
                            <input type="button" class="btn btn-default btn-md" style="margin-left:6px;" value="选发票号" onclick="ShowInvoicePanel()" />
                        </div>
                    </td>
                }
                else
                {
                    <th class="formTitle"></th>
                    <td class="formValue"></td>
                }
            </tr>
            <tr>
                <th class="formTitle">入院日期：</th>
                <td class="formValue" colspan="2">
                    <label id="lblRyrq"></label>
                </td>
                <th class="formTitle"><p class="ztjsyc"><span style="color:red">*</span>出院日期：</p></th>
                <td class="formValue" colspan="2">
                    <input id="cyrq" type="text" class="form-control  form-an input-wdatepicker ztjsyc" style="float: left; margin-left: 5px; width:90%" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">应收款：</th>
                <td class="formValue">
                    ￥<label id="yingshoukuan"></label>
                </td>
            </tr>

            <tr id="trYjjzf" style="display:none;">
                <th class="formTitle">预交金余额：</th>
                <td class="formValue">
                    ￥<label id="yjjye"></label>
                </td>
                <td class="formValue" colspan="4">
                    <div class="ckbox ztjsyc">
                        <input id="ckyjjzfuse" type="checkbox"><label for="ckyjjzfuse">预交金支付</label>
                    </div>
                    <div id="dv_yjjtye">
                        <div class="ckbox ztjsyc">
                            <input id="ckyjjzfyeqt" type="checkbox"><label for="ckyjjzfyeqt">余额全退</label>
                        </div>
                        <span style="font-weight:bold;color:red;">可退余额:￥<label id="yeqtje">0.00</label></span>
                    </div>
                </td>
                @*<td class="formValue" id="td_accountcharge">
                        <input type="button" class="btn btn-default" id="btn_czyjj" style="color: red;" value="余额不足，前往充值" onclick="InpAccountDeposit();"  />
                    </td>*@
            </tr>
            <tr style="display:none;">
                <th class="formTitle">支付方式：</th>
                <td class="formValue" colspan="2">
                    <select id="zffs1" class="form-control  form-an" style="width:90%">
                        <option value="">==请选择==</option>
                    </select>
                </td>
            </tr>
            <tr class="isShowZFFS" style="display:none;">
                <th class="formTitle">第二支付方式：</th>
                <td class="formValue">
                    <select id="zffs2" class="form-control form-an" style="width:90%">
                        <option value="">==可选择==</option>
                    </select>
                </td>
                <th class="formTitle">收款：</th>
                <td class="formValue" colspan="2">
                    <input type="text" id="zfje2" class="form-control form-an" style="width:90%" />
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <hr />
                </td>
            </tr>
            <tr>
                <th class="formTitle ztjsyc" style="color:red;">预交金抵扣：</th>
                <td class="formValue ztjsyc" style="font-size:large" colspan="2">￥<label id="yjjzfje">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle ztjsyc" style="color:red;">待缴金额：</th>
                <td class="formValue ztjsyc" style="font-size:large" colspan="2">￥<label id="djje">0.00</label></td>
            </tr>
            <tr class="trUseZk" style="display:none;">
                <th class="formTitle" style="color:red;">折扣比例：</th>
                <td class="formValue">
                    <input id="zkbl" type="text" class="form-control  form-an" style="width:40%; float:left;" />
                    <span style="line-height:25px; color:red;">%</span>
                </td>

                <th class="formTitle" style="display:none;">折扣金额：</th>
                <td class="formValue" style="display:none;">
                    <input id="zkje" type="text" class="form-control  form-an" />
                </td>
            </tr>
            <tr>
                <th class="formTitle" style="color:red;">
                    <i id="zffsCircle" class="fa fa-plus-circle plusToggleCircle" aria-hidden="true" style="width:30px;margin-left: 10px; color: #6ff3ad; font-size: large;"></i>
                    窗口实收：
                </th>
                <td class="formValue" style="font-size:large" colspan="2">
                    <input type="text" id="djjess" class="form-control required zffsinput" onfocus="clearnum()" autocomplete="off" onkeyup="setzfje('')" onchange="verifyZffs('')" style="width:90%" value="0.00" oninput="inputnum(this)" />
                </td>
                <th class="formTitle">支付方式：</th>
                <td class="formValue" colspan="2">
                    <select id="djjesszffs" class="form-control  form-an" style="width:90%">
                        <option value="">==请选择==</option>
                    </select>
                </td>
            </tr>

            @*<tr class="trUseZk" style="display:none;">
                    <th class="formTitle">折后应收款：</th>
                    <td class="formValue">
                        ￥<label id="zhysk"></label>
                    </td>
                </tr>*@
            <tr hidden>
                <th class="formTitle" style="color:red;">收款（old）：</th>
                <td class="formValue" style="font-size:large" colspan="2">
                    <input type="text" id="zfje1" class="form-control form-an" style="width:90%" />
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <hr />
                </td>
            </tr>

        </table>
        <table class="form">
            <tr>
                <th></th>
                <td></td>
                <td></td>
                <th class="formTitle" style="color:red;font-weight:bold;">合计实收款：</th>
                <td class="formValue" style="font-size:large" colspan="2">￥<label id="hjssk">0.00</label></td>
            </tr>
            <tr>
                <th></th>
                <td colspan="2"></td>
                <th class="formTitle ztjsyc" style="color:red;font-weight:bold;">找零：</th>
                <td class="formValue ztjsyc" style="font-size:large" colspan="2">￥<label id="zhaoling">0.00</label></td>
            </tr>
            <tr id="tr_yjjtye" hidden>
                <th></th>
                <td colspan="2"></td>
                <th class="formTitle ztjsyc" style="color:red;font-weight:bold;">其中：含预交金退余额</th>
                <td class="formValue ztjsyc" style="font-weight:bold;">（ ￥<label id="yjjtye">0.00</label> ）</td>
            </tr>
        </table>
    </div>
</div>

<script>
    var medicalInsurance = '@medicalInsurance';
    var defaultPayMethod = "@(defaultPayMethod)";
    var SettPayBalance='@(SettPayBalance)';
    var sfyxdzzf = '@(sfyxdzzf)';
    var zyh = $.request("zyh");
    var ryrq = $.request("ryrq");
    var cyrq = $.request("cyrq");
    var ztjs = $.request("ztjs");
    var patid = $.request("patid");
    if (!!cyrq) {
        cyrq = $.getDate({ date: cyrq });   //格式化
    }

    ///中途结算
    if (ztjs) {
        //$('.ztjsyc').hide();

    }
    var interfaceWithCPOE = '@(interfaceWithCPOE)';
    //预交金余额
    var yjjye = 0;
    var withYjj = '@(withYjj)';
    var yjjzffs = "";
    //结算总金额
    var zje = ovpraseFloat($.request("zje"));
    //支付应收 结算时应收（zje = 可报 + 结算时应收 + 等等）
    var orglxjzfys = ovpraseFloat($.request("xjzfys"));
    //有折扣时不等 original
    var xjzfys = orglxjzfys;    //有折扣时会不等

    //医保相关
    var ybjyFeeReturn;
    var isYbjy = $.request("isYbjy");
    var brxz = $.request("brxz");
    var brxzmc = $.request("brxzmc");
    var strdyjylsh = "";//抵用账户流水号，重庆医保，为了更新抵用落地表的jsnm
    var xnhjyFeeReturn;
    var isXnhjy = $.request("isXnhjy");
    var cqPatInfo = JSON.parse(sessionStorage.getItem('cqPatInfo'));
    var zhdyList = "";
    if (isYbjy == 'true') {
        debugger;
        ybjyFeeReturn = JSON.parse(sessionStorage.getItem('ybjyFeeReturn'));
        if (!!ybjyFeeReturn) {
            if (!medicalInsurance) {
                $.modalAlert("程序未动态配置医保地，请配置后重试", 'warning');
                $.modalClose();
            }
            if (cqPatInfo.ybVer === "gjyb")
	        {
                $('#divQHDYbFee').show();
                $('#divShYbV5Fee').remove();
	            var mzjzje = 0.000;//民政救助金额
	            var xjzfje = 0.000;//医保的现金支付金额
	            var zfxjzf = 0.000;//非医保现金支付金额

	            //医保的现金支付金额
	            xjzfje = ovpraseFloat(ybjyFeeReturn.psn_cash_pay) ;
	            //非医保现金金额
	            zfxjzf = ovpraseFloat(ybjyFeeReturn.his_hisfyze) -
			        ovpraseFloat(ybjyFeeReturn.ybzje);
	            //计算现金支付
	            var calc_xjzf = ovpraseFloat(ybjyFeeReturn.psn_cash_pay) +
			        ovpraseFloat(ybjyFeeReturn.his_hisfyze) -
			        ovpraseFloat(ybjyFeeReturn.ybzje);
	            ybjyFeeReturn.calc_xjzf = calc_xjzf;
	            //
	            zje = ovpraseFloat(ybjyFeeReturn.his_hisfyze);
	            orglxjzfys = ovpraseFloat(ybjyFeeReturn.calc_xjzf);
	            xjzfys = orglxjzfys;    //有折扣时会不等

	            mzjzje = ovpraseFloat(ybjyFeeReturn.maf_pay);
	            !!ybjyFeeReturn.his_hisfyze && $('#cq_fyze').html(ovpraseFloat(ybjyFeeReturn.his_hisfyze).toFixed(2));
	            !!ybjyFeeReturn.calc_xjzf && $('#cq_xjzf').html(ovpraseFloat(ybjyFeeReturn.calc_xjzf).toFixed(2));//总现金支付
	            !!zfxjzf && $('#zf_xjzf').html(zfxjzf.toFixed(2));//非医保现金支付
	            !!xjzfje && $('#yb_xjzf').html(xjzfje.toFixed(2));//医保现金支付
	            !!ybjyFeeReturn.acct_pay && $('#cq_zhzf').html(ovpraseFloat(ybjyFeeReturn.acct_pay).toFixed(2));
	            !!ybjyFeeReturn.hifp_pay && $('#cq_tczf').html((ovpraseFloat(ybjyFeeReturn.hifp_pay)));
	            !!ybjyFeeReturn.hifob_pay && $('#cq_delp').html(ovpraseFloat(ybjyFeeReturn.hifob_pay).toFixed(2));
	            !!ybjyFeeReturn.cvlserv_pay && $('#cq_gwybz').html(ovpraseFloat(ybjyFeeReturn.cvlserv_pay).toFixed(2));
	            !!ybjyFeeReturn.maf_pay && $('#cq_mzbz').html(mzjzje);

	            !!ybjyFeeReturn.hosp_part_amt && $('#dbzddyljgdz').html((ovpraseFloat(ybjyFeeReturn.hosp_part_amt)));

	            !!ybjyFeeReturn.hifes_pay && $('#cq_qybxzc').html(ovpraseFloat(ybjyFeeReturn.hifes_pay).toFixed(2));
	            !!ybjyFeeReturn.hifmi_pay && $('#cq_jmdbzc').html(ovpraseFloat(ybjyFeeReturn.hifmi_pay).toFixed(2));
	            !!ybjyFeeReturn.oth_pay && $('#cq_qt').html(ovpraseFloat(ybjyFeeReturn.oth_pay).toFixed(2));
	            !!ybjyFeeReturn.acct_mulaid_pay && $('#cq_zhgjzf').html(ovpraseFloat(ybjyFeeReturn.acct_mulaid_pay).toFixed(2));
            }
            else if (cqPatInfo.ybVer === "shanghaiV5"){
                $('#divQHDYbFee').remove();
                $('#divShYbV5Fee').show();
                var xjzfje = 0.000;//医保的现金支付金额
                var zfxjzf = 0.000;//非医保现金支付金额
                var yjs = 0.000;//预交金后账户余额
                //医保的现金支付金额
                xjzfje = ovpraseFloat(ybjyFeeReturn.qfdxjzfs) + ovpraseFloat(ybjyFeeReturn.tcdxjzfs)
                    + ovpraseFloat(ybjyFeeReturn.fjdxjzfs);
                //非医保现金金额
                zfxjzf = ovpraseFloat(ybjyFeeReturn.his_hisfyze) -
                    ovpraseFloat(ybjyFeeReturn.ybjsfwfyze);
                //计算现金支付
                var calc_xjzf = ovpraseFloat(zfxjzf) +
                    ovpraseFloat(xjzfje) ;
                ybjyFeeReturn.calc_xjzf = calc_xjzf;

                orglxjzfys = ovpraseFloat(ybjyFeeReturn.calc_xjzf);
                xjzfys = orglxjzfys;    //有折扣时会不等

                //yjs = calc_xjzf - zhye;//计算预交金后账户余额

                !!ybjyFeeReturn.his_hisfyze && $('#ZFY').html(ovpraseFloat(ybjyFeeReturn.his_hisfyze).toFixed(2));
                !!ybjyFeeReturn.calc_xjzf && $('#XJZF').html(ovpraseFloat(ybjyFeeReturn.calc_xjzf).toFixed(2));//总现金支付
                !!zfxjzf && $('#ZFJF').html(zfxjzf.toFixed(2));//非医保现金支付
                !!xjzfje && $('#YBJF').html(xjzfje.toFixed(2));//医保现金支付

                !!ybjyFeeReturn.curaccountpay && $('#curaccountpay').html(ovpraseFloat(ybjyFeeReturn.curaccountpay).toFixed(2));
                !!ybjyFeeReturn.hisaccountpay && $('#hisaccountpay').html(ovpraseFloat(ybjyFeeReturn.hisaccountpay).toFixed(2));
                !!ybjyFeeReturn.zfdxjzfs && $('#zfdxjzfs').html(ovpraseFloat(ybjyFeeReturn.zfdxjzfs).toFixed(2));
                !!ybjyFeeReturn.zfdlnzhzfs && $('#zfdlnzhzfs').html(ovpraseFloat(ybjyFeeReturn.zfdlnzhzfs).toFixed(2));

                !!ybjyFeeReturn.tcdzhzfs && $('#tcdzhzfs').html(ovpraseFloat(ybjyFeeReturn.tcdzhzfs).toFixed(2));
                !!ybjyFeeReturn.tcdxjzfs && $('#tcdxjzfs').html((ovpraseFloat(ybjyFeeReturn.tcdxjzfs)));
                !!ybjyFeeReturn.tczfs && $('#tczfs').html(ovpraseFloat(ybjyFeeReturn.tczfs).toFixed(2));
                !!ybjyFeeReturn.fjdzhzfs && $('#fjdzhzfs').html(ovpraseFloat(ybjyFeeReturn.fjdzhzfs).toFixed(2));
                !!ybjyFeeReturn.fjdxjzfs && $('#fjdxjzfs').html(ovpraseFloat(ybjyFeeReturn.fjdxjzfs).toFixed(2));

                !!ybjyFeeReturn.fjzfs && $('#fjzfs').html(ovpraseFloat(ybjyFeeReturn.fjzfs).toFixed(2));

                !!ybjyFeeReturn.curaccountamt && $('#curaccountamt').html(ovpraseFloat(ybjyFeeReturn.curaccountamt).toFixed(2));
                !!ybjyFeeReturn.hisaccountamt && $('#hisaccountamt').html(ovpraseFloat(ybjyFeeReturn.hisaccountamt).toFixed(2));
                !!ybjyFeeReturn.ybjsfwfyze && $('#ybjsfwfyze').html(ovpraseFloat(ybjyFeeReturn.ybjsfwfyze).toFixed(2));
                !!ybjyFeeReturn.fybjsfwfyze && $('#fybjsfwfyze').html(ovpraseFloat(ybjyFeeReturn.fybjsfwfyze).toFixed(2));
                //共济账户
                !!ybjyFeeReturn.fjdgjzhzfs && $('#fjdgjzhzfs').html(ovpraseFloat(ybjyFeeReturn.fjdgjzhzfs).toFixed(2));
                //!!ybjyFeeReturn.zfdgjzhzfs && $('#zfdgjzhzfs').html(ovpraseFloat(ybjyFeeReturn.zfdgjzhzfs).toFixed(2));
                !!ybjyFeeReturn.qfdgjzhzfs && $('#qfdgjzhzfs').html(ovpraseFloat(ybjyFeeReturn.qfdgjzhzfs).toFixed(2));
                !!ybjyFeeReturn.tcdgjzhzfs && $('#tcdgjzhzfs').html(ovpraseFloat(ybjyFeeReturn.tcdgjzhzfs).toFixed(2));
            }
        }
        else {
            //异常
            orglxjzfys = xjzfys = zje = 0;
            $.modalAlert("医保支付异常，请重试", "error");
            $.modalClose();
        }
    }

    if (isXnhjy == 'true') {
        xnhjyFeeReturn = JSON.parse(sessionStorage.getItem('xnhjyFeeReturn'));
        if (!!xnhjyFeeReturn) {
            if (!medicalInsurance) {
                $.modalAlert("程序未动态配置医保地，请配置后重试", 'warning');
                $.modalClose();
            }
            //如果走贵安医保逻辑
            if (medicalInsurance === "guian") {
                $('#divGuiAnXnhFee').show();
                $('#divGuiAnYbFee').remove();
                $('#divzhdy').remove();
                //zje = ovpraseFloat(xnhjyFeeReturn.his_hisfyze);
                orglxjzfys = xnhjyFeeReturn.nhxjzf + ovpraseFloat(zje) - xnhjyFeeReturn.totalCost;
                xjzfys = orglxjzfys;    //有折扣时会不等
                //
                //!!xnhjyFeeReturn.totalCost && $('#totalCost').html(ovpraseFloat(xnhjyFeeReturn.totalCost).toFixed(2));
                !!xnhjyFeeReturn.undulatingLine && $('#undulatingLine').html(ovpraseFloat(xnhjyFeeReturn.undulatingLine).toFixed(2));
                !!xnhjyFeeReturn.accRedeem && $('#accRedeem').html(ovpraseFloat(xnhjyFeeReturn.accRedeem).toFixed(2));
                !!xnhjyFeeReturn.compensateCost && $('#compensateCost').html(ovpraseFloat(xnhjyFeeReturn.compensateCost).toFixed(2));
                !!xnhjyFeeReturn.civilCost && $('#civilCost').html(ovpraseFloat(xnhjyFeeReturn.civilCost).toFixed(2));
                !!xnhjyFeeReturn.insureCost && $('#insureCost').html(ovpraseFloat(xnhjyFeeReturn.insureCost).toFixed(2));
                !!xnhjyFeeReturn.salvaJSCost && $('#salvaJSCost').html(ovpraseFloat(xnhjyFeeReturn.salvaJSCost).toFixed(2));
                !!xnhjyFeeReturn.bottomRedeem && $('#bottomRedeem').html(ovpraseFloat(xnhjyFeeReturn.bottomRedeem).toFixed(2));
                !!xnhjyFeeReturn.salvaFPCost && $('#salvaFPCost').html(ovpraseFloat(xnhjyFeeReturn.salvaFPCost).toFixed(2));
                !!xnhjyFeeReturn.salvaQTCost && $('#salvaQTCost').html(ovpraseFloat(xnhjyFeeReturn.salvaQTCost).toFixed(2));
                !!xnhjyFeeReturn.totalCost && $('#nhzje').html(ovpraseFloat(xnhjyFeeReturn.totalCost).toFixed(2));
                !!xnhjyFeeReturn.nhxjzf && $('#nhxjzf').html(ovpraseFloat(xnhjyFeeReturn.nhxjzf).toFixed(2));
                $('#hisfyze').html(ovpraseFloat(zje).toFixed(2));
                $('#zfze').html(ovpraseFloat(ovpraseFloat(zje).toFixed(2) - ovpraseFloat(xnhjyFeeReturn.totalCost).toFixed(2)).toFixed(2));
            }
        }
        else {
            //异常
            orglxjzfys = xjzfys = zje = 0;
            $.modalAlert("医保支付异常，请重试", "error");
            $.modalClose();
        }
    }
    if (brxz == 0 || brxzmc == "自费") {
        $('.trUseZk').show();
    } else {
        $(".trUseZk").hide();
    }
    $(function (){
        if (!!zyh) {
            $('#lblZyh').html(zyh);
        }
        if (!!ryrq) {
            $('#lblRyrq').html(ryrq);
        }
        if (!!cyrq) {
            $('#cyrq').val(cyrq);
            if (interfaceWithCPOE == 'True') {
                $('#cyrq').attr("disabled", "disabled");
            }
        }
        else {
            //否则默认赋值当天
            $('#cyrq').val($.getDate());
        }

        //应收款
        if (!!xjzfys || xjzfys == 0) {
            $('#yingshoukuan').html(xjzfys.toFixed(2));
            //$('#zhysk').html(xjzfys.toFixed(2));
            //$('#zfje1').val(xjzfys.toFixed(2));
            //if (!((defaultPayMethod == '0') || $('#ckyjjzfyeqt').is(':checked'))) {
            //    $('#zfje1').val(xjzfys.toFixed(2));
            //}
            $('#hjssk').html(xjzfys.toFixed(2));
            $('#zhaoling').html('0.00');
            $('#djje').html('0.00');
            $('#yjjtye').html('0.00');
        }

        if (withYjj == 'True') {
            var yjjUrl = "/SystemManage/InpatientAccountManage/GetZyAccount?zyh=" + zyh;
            //if (medicalInsurance === "qinhuangdao") {
                yjjUrl += '&zhxz='+@((int)EnumXTZHXZ.ZYYJKZH);
            //}
            $.najax({
                url: yjjUrl,
                cache: false,
                async: false,
                alertbierror: false,
                success: function (zhyeData) {
                    if (zhyeData && zhyeData.data) {
                        yjjye = zhyeData.data.zhye;
                    }
                }
            });
        }
        debugger;
        if (yjjye) {
            $('#trYjjzf').show();
            $('#yjjye').html(ovpraseFloat(yjjye).toFixed(2));
            if (ovpraseFloat(yjjye) > 0) {
                $('#ckyjjzfuse').attr("checked", "checked");
            }
            yjjReset();

        }
        else {
            $('#yjjzfje').html(ovpraseFloat(0).toFixed(2));
            hjsskZhaolingCalNew();
        }

        //取消预交金支付时 同时取消余额全退
        $("#ckyjjzfuse").click(function () {
            debugger;
            czzfje();
            if ($('#ckyjjzfuse').is(':checked')) {
                if ($('#ckyjjzfyeqt').is(':checked')) {
                    $('#ckyjjzfyeqt').trigger('click');
                }
                else {
                    yjjReset();
                }
                yjjyetq();
            }
            else {
                $('#yjjzfje').html(ovpraseFloat(0).toFixed(2));
                if ($('#ckyjjzfyeqt').is(':checked')) {
                    $('#ckyjjzfyeqt').trigger('click');
                }
                hjsskZhaolingCalNew();
            }
        });
        $("#ckyjjzfyeqt").click(function () {
            debugger;
            yjjyetq();
        });


        //现场窗口缴费支付方式-except预交金
        $("#djjesszffs").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                $.each(top.clients.SysForCashPayList, function (key, value) {
                    if (value.xjzffs == '3') {
                        return; //不显示该支付方式
                    }
                    if (value.xjzffs == "0") {
                        $('#djjesszffs').append('<option value="' + value.xjzffs + '" selected >' + value.xjzffsmc + '</option>');

                    }
                    else {
                        $('#djjesszffs').append('<option value="' + value.xjzffs + '">' + value.xjzffsmc + '</option>');
                    }
                });
                return resultObjArr;
            }
        });

        yjjRefresh();
        initFPH();
        initPage();
	});

    function yjjyetq()
    {
        if ($('#ckyjjzfyeqt').is(':checked')) {
            if (!($('#ckyjjzfuse').is(':checked'))) {
                $("#ckyjjzfuse").trigger('click');
            }
            $("#tr_yjjtye").show();
            //预交金支付方式，‘余额全退’
            if (!!yjjye && yjjye >= xjzfys) {
                $('#yeqtje').html((yjjye - xjzfys).toFixed(2));
                $('#yjjtye').html((yjjye - xjzfys).toFixed(2));
                $('#yjjzfje').html(ovpraseFloat(xjzfys).toFixed(2));
                hjsskZhaolingCalNew();
            }
            else if (!!yjjye)
            {
                $('#yeqtje').html((0).toFixed(2));
                $('#yjjtye').html((0).toFixed(2));
                $('#yjjzfje').html(ovpraseFloat(yjjye).toFixed(2));
                hjsskZhaolingCalNew();
            }
        }
        else {
            $("#tr_yjjtye").hide();
            $('#yjjtye').html(ovpraseFloat(0).toFixed(2));
            hjsskZhaolingCalNew();
        }
    }
    $("#cardType").click(function() {
        if ($("#cardType").prop("checked")) {
            $("#zhdy").removeAttr("disabled");
        } else {
            $("#zhdy").attr("disabled", "disabled");
        }
    })
    function initPage() {
        if (sfyxdzzf == true) {
            $(".isShowZFFS").show();
        }
    }

    var theAcceptClickCallBack = null;
    function AcceptClick(callBack) {
        theAcceptClickCallBack = callBack;

        //填写的收费日期 等
        var obj = getPostData();
        if (obj) {
            //190328add移动支付
            if (!CheckPayOK(obj)) {
                return;
            }
            callBack(obj, outTradeNo);
        }
    }

    function getPostData() {
        var isSuccsee = true;
        if (ryrq == "" || !ryrq) {
            $.modalAlert('缺少入院日期', 'warning');
            return false;
        }
        var cyrq = $('#cyrq').val();
        if (cyrq == "" || !cyrq) {
            $.modalAlert('缺少出院日期', 'warning');
            return false;
        }
        if (cyrq < ryrq) {
            $.modalAlert("出院日期小于入院日期,请确认。", 'warning');
            return;
        }
        if ($.getDate() < cyrq) {
            $.modalAlert('出院日期错误', 'warning');
            return false;
        }
        var fph = $('#txtfph').html();
        var djjesszffs = $('#djjesszffs option:selected').val();
        var djjess = $('#djjess').val();
        if (djjesszffs == "" && ovpraseFloat(djjess) > 0) {
            $.modalAlert('请选择支付方式', 'error');
            return false;    //支付方式选择错误
        }
        else if (ovpraseFloat(djjess) < 0) {
            $.modalAlert('窗口实收金额异常', 'error');
            return false;
        }
        //
        var hjssk = $('#hjssk').html();
        hjssk = !!ovpraseFloat(hjssk) ? ovpraseFloat(hjssk) : 0;
        var zhaoling = $('#zhaoling').html();
        zhaoling = !!ovpraseFloat(zhaoling) ? ovpraseFloat(zhaoling) : 0;
        var yjjtye = $('#yjjtye').text();
        var djjess = $('#djjess').val();
        var zkbl = $('#zkbl').val();
        zkbl = !!parseInt(zkbl) ? (parseInt(zkbl) / 100).toFixed(2) : 0;
        //
        if ($('#txtfph').length == 0) {
            fph = null;
        }
        else {
            if (!fph) {
                $.modalAlert('请选择发票号', 'warning');
                return false;
            }
        }
        var yjjzfje = $("#yjjzfje").text().trim();
        if ((ovpraseFloat(hjssk) + ovpraseFloat(yjjtye)).toFixed(2) != $.addNum(xjzfys, zhaoling).toFixed(2) || zhaoling < 0) {
            $.modalAlert("找零金额异常", "error");
            return false;
        }
        var PatZfList=getzfArrayData();
        var xjwc=(ovpraseFloat($("#yingshoukuan").html())-(ovpraseFloat($("#djje").html())+ovpraseFloat(yjjzfje))).toFixed(2);
        return {
            fph: fph, cyrq: cyrq
            //, zffs1: zffs1, zfje1: zfje1, zffs2: zffs2, zfje2: zfje2
            , zje: ovpraseFloat(zje).toFixed(2), orglxjzfys: orglxjzfys, xjzfys: ovpraseFloat(xjzfys).toFixed(2)
            , ssk: hjssk, zhaoling: zhaoling, dyjylsh: strdyjylsh
            , yjjzfje: ovpraseFloat(yjjzfje).toFixed(2), yjjtye: ovpraseFloat(yjjtye).toFixed(2)
            ,PatZfList:PatZfList,xjwc:xjwc,jmje:ovpraseFloat($("#zkje").val()).toFixed(2)
            , djjesszffs: djjesszffs, djjess: ovpraseFloat(djjess).toFixed(2), zkbl: ovpraseFloat(zkbl).toFixed(2)
        };
    }

    function getPostDatabak() {
        var isSuccsee = true;
        if (ryrq == "" || !ryrq) {
            $.modalAlert('缺少入院日期', 'warning');
            return false;
        }
        var cyrq = $('#cyrq').val();
        if (cyrq == "" || !cyrq) {
            $.modalAlert('缺少出院日期', 'warning');
            return false;
        }
        if (cyrq < ryrq) {
            $.modalAlert("出院日期小于入院日期,请确认。", 'warning');
            return;
        }
        if ($.getDate() < cyrq) {
            $.modalAlert('出院日期错误', 'warning');
            return false;
        }
        var fph = $('#txtfph').html();
        var zffs1 = $('#zffs1').val();
        !(!!zffs1 || zffs1 == '0') ? $('#zfje1').val('') : undefined;
        var zfje1 = $('#zfje1').val();
        zfje1 = (!!zffs1 || zffs1 == '0') && !!ovpraseFloat(zfje1) ? ovpraseFloat(zfje1) : 0;
        if (zffs1 == '3' && yjjye) {
            if (!(parseFloat(zfje1) <= parseFloat(yjjye) || parseFloat(zfje1) <= parseFloat(xjzfys))) {
                $.modalAlert("预交金不足，不能进行结算，请充值预交金或选择其它支付方式", "error");
                return false;
            }
        }
        //
        var zffs2 = $('#zffs2').val();
        !(!!zffs2 || zffs2 == '0') ? $('#zfje2').val('') : undefined;
        var zfje2 = $('#zfje2').val();
        zfje2 = (!!zffs2 || zffs2 == '0') && !!ovpraseFloat(zfje2) ? ovpraseFloat(zfje2) : 0;
        //
        if (zffs1 === zffs2 && !!zffs2) {
            $.modalAlert('支付方式选择错误', 'error');
            return false;    //支付方式选择错误
        }
        if (!!!zffs1 && !!zffs2) {
            $.modalAlert('支付方式选择错误', 'error');
            return false;    //支付方式选择错误
        }
        //
        var hjssk = $('#hjssk').html();
        hjssk = !!ovpraseFloat(hjssk) ? ovpraseFloat(hjssk) : 0;
        var zhaoling = $('#zhaoling').html();
        zhaoling = !!ovpraseFloat(zhaoling) ? ovpraseFloat(zhaoling) : 0;
        //
        if ($('#txtfph').length == 0) {
            fph = null;
        }
        else {
            if (!fph) {
                $.modalAlert('请选择发票号', 'warning');
                return false;
            }
        }
        //
        if (ovpraseFloat(hjssk).toFixed(2) != ovpraseFloat(ovpraseFloat(zfje1) + ovpraseFloat(zfje2)).toFixed(2)) {
            $.modalAlert("收款金额异常", "error");
            return false;
        }
        if (ovpraseFloat(hjssk).toFixed(2) != $.addNum(xjzfys, zhaoling).toFixed(2) || zhaoling < 0) {
            $.modalAlert("找零金额异常", "error");
            return false;
        }
        return {
            fph: fph, cyrq: cyrq
            , zffs1: zffs1, zfje1: zfje1, zffs2: zffs2, zfje2: zfje2
            , zje: ovpraseFloat(zje).toFixed(2), orglxjzfys: orglxjzfys, xjzfys: ovpraseFloat(xjzfys).toFixed(2)
            , ssk: hjssk, zhaoling: zhaoling, dyjylsh: strdyjylsh
        };
    }

    //common start
    function ovpraseFloat(val) {
        if (!val) {
            val = 0;
        }
        return parseFloat(val);
    }
    //页面进来，加载发票号
    function initFPH() {
        if (!($("#txtfph").length == 1)) {
            return;
        }
        $.najax({
            url: "/OutpatientManage/OutpatientReg/GetInvoice?r=" + Math.random(),
            dataType: "text",
            cache: false,
            success: function (data) {
                $("#txtfph").html(data);
            }
        });
    }

    //弹出发票号的窗口
    function ShowInvoicePanel() {
        $.modalOpen({
            id: "InvoiceNoPanel",
            title: "选发票号",
            url: "/OutpatientManage/OutpatientReg/ChooseInvoice?from=ConfirmFeeForm",
            width: "300px",
            height: "200px",
            callBack: function (iframeId) {
                top.frames[iframeId].checkFPH();//窗口点确定的回调函数
            }
        });
    }

    //
    $('#zfje1').keyup(function () {
        hjsskZhaolingCalNew();
        //if ($('#ckyjjzfyeqt').is(':checked')) {
        //    $('#ckyjjzfyeqt').trigger('click');
        //}
        //if ($("#djjesszffs option:selected").val() == "" && ovpraseFloat($("#djjess").val())!=0) {
        //    $.modalAlert('请选择支付方式', 'error');
        //}
    });
    $('#zfje1').change(function () {
        hjsskZhaolingCalNew();
        //if ($('#ckyjjzfyeqt').is(':checked')) {
        //    $('#ckyjjzfyeqt').trigger('click');
        //}
        if ($("#djjesszffs option:selected").val() == "" && ovpraseFloat($("#djjess").val()) != 0) {
            $.modalAlert('请选择支付方式', 'error');
        }
    });

    $('#zkje,#zkbl').keyup(function () {
        discountCal();
    });
    //折扣比例，折扣金额 计算折扣
    function discountCal() {
        debugger;
        var zkje = ovpraseFloat(0).toFixed(2);//$('#zkje').val();
        var zkbl = $('#zkbl').val();

        var je = calZkhMoney(ovpraseFloat(orglxjzfys).toFixed(2), zkje, zkbl);
        if (je === false) {
            //折扣计算失败 只能重置折扣
            $('#zkje').val('');
            $('#zkbl').val('');
            xjzfys = orglxjzfys;
        }
        else {
            xjzfys = je;
        }
        $("#zkje").val((ovpraseFloat(orglxjzfys) - ovpraseFloat(xjzfys)).toFixed(2));
        $("#djjess").val(ovpraseFloat(0).toFixed(2));
        //
        //$('#zhysk').html(xjzfys);
        if ($('#ckyjjzfuse').is(':checked')) {
            xjzfys=sswrjeCz();
            $('#yjjzfje').text(xjzfys);
            if(yjjye>xjzfys){
                $('#yeqtje').html((yjjye - xjzfys).toFixed(2));
            }
            else{
                $('#yeqtje').html((0).toFixed(2));
            }

        }
        hjsskZhaolingCalNew();
        yjjyetq();
    }
    //根据折扣比例和折扣金额计算 折后金额
    function calZkhMoney(je, zkje, zkbl) {
        debugger;
        if (je == 0) {
            return 0;
        }
        if (validMoney(je, zkje, zkbl)) {
            if (zkbl) {
                //折扣比例
                var decimalbl = (parseInt(zkbl) / 100).toFixed(2);
                je = roundingBy4she6ru5chengshuang(ovpraseFloat(ovpraseFloat(je) * decimalbl), 2);
            }
            if (zkje) {
                if (ovpraseFloat(zkje) > ovpraseFloat(je)) {
                    $.modalAlert('折扣异常，产生负应收', 'warning');
                    return false;
                }
                //折扣金额
                je = roundingBy4she6ru5chengshuang(ovpraseFloat((ovpraseFloat(je) - ovpraseFloat(zkje))), 2);
            }
            return ovpraseFloat(je);
        }
        else {
            return false;
        }
    }

    //验证金额格式是否正确
    function validMoney(zqje, zkje, zkbl) {
        if (zqje == '' || zqje == '0.00') {
            $.modalAlert('费用无效', 'warning');
            return false;
        }
        //折扣金额
        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
        if (!!zkje) {
            if (!reg.test(zkje) || zkje == '') {
                $.modalAlert('折扣金额格式有误', 'warning');
                return false;
            }
        }

        if (ovpraseFloat(zkje) > ovpraseFloat(zqje)) {
            $.modalAlert('折扣金额不能大于折前金额', 'warning');
            return false;
        }

        //折扣比例
        var blreg = /(^[1-9][0-9]$)|(^100&)|(^[1-9]$)$/;
        if (!!zkbl) {
            if (!reg.test(zkbl)) {
                $.modalAlert('折扣比例格式有误', 'warning');
                return false;
            }
        }
        if (parseInt(zkbl) > 100) {
            $.modalAlert('折扣比例不能大于100', 'warning');
            return false;
        }
        return true;
    }
    //计算 根据 支付应收、支付方式 计算合计实收款、找零  不支持多种支付方式
    function hjsskZhaolingCal() {
        var djje = 0.00; //代缴金额
        if (!$('#zffs1').val() && $('#zfje1').val() != 0) {
            //未选择支付方式，对应金额要置为0.00
            $('#zfje1').val('0.00');
            djje = xjzfys.toFixed(2);
        }
        var zfje1 = $('#zfje1').val();
        if (!zfje1) {
            zfje1 = '0.00';
        }

        var hjssk = ovpraseFloat(zfje1);  //多种支付方式合计实收
        djje = ovpraseFloat(xjzfys - hjssk).toFixed(2);
        if (djje < 0) {
            djje = 0.00;
        }
        $('#djje').html(ovpraseFloat(djje).toFixed(2));  //待缴
        $('#hjssk').html(hjssk + ovpraseFloat(djje));
        var zhaoling = ovpraseFloat(hjssk - xjzfys);
        if (zhaoling < 0) {
            zhaoling = 0.00;
        }
        $('#zhaoling').html(zhaoling.toFixed(2));
    }

    function hjsskZhaolingCalNew() {
        var yjjzf = ovpraseFloat($("#yjjzfje").text().trim()).toFixed(2);//预交金抵扣
        var djje = 0.00; //代缴金额
        //var djjess = ovpraseFloat($("#djjess").val());  //窗口实收
        var djjess=CalculatedAmount();//窗口实收合计
        var zhaoling = 0.00;
        var hjssk = 0.00;
        var yjjtye = ovpraseFloat($("#yjjtye").text().trim()).toFixed(2);
        if (!!yjjzf && ovpraseFloat(yjjzf)>=0) {
            xjzfys=sswrjeCz();
            djje = (ovpraseFloat(xjzfys) - ovpraseFloat(yjjzf)).toFixed(2);
            if (ovpraseFloat(djje) < 0) {
                //djje = 0.00;
                $("#djje").html(ovpraseFloat(0).toFixed(2));

                if (djjess<=0) {
                    $("#djjess").val(ovpraseFloat(djje).toFixed(2));
                    djjess = ovpraseFloat($("#djjess").val());
                }

                $('#hjssk').html((ovpraseFloat(yjjzf) + ovpraseFloat(djjess)).toFixed(2));
                zhaoling = (Math.abs(ovpraseFloat(djje)) + djjess + ovpraseFloat(yjjtye)).toFixed(2);
                $('#zhaoling').html(zhaoling);
            }
            else {
                $("#djje").html(ovpraseFloat(djje).toFixed(2));
                if (djjess <= 0) {
                    $("#djjess").val(ovpraseFloat(djje).toFixed(2));
                    djjess = ovpraseFloat($("#djjess").val());
                }

                hjssk = (ovpraseFloat(yjjzf) + ovpraseFloat(djjess)).toFixed(2);
                $('#hjssk').html(hjssk);
                zhaoling = (ovpraseFloat(hjssk) - ovpraseFloat(xjzfys) + ovpraseFloat(yjjtye)).toFixed(2);
                $('#zhaoling').html(zhaoling);
            }
        }
    }
    //多支付方式金额合计
    function CalculatedAmount()
    {
        var cksshj=ovpraseFloat($("#djjess").val());
        var number = $('#tablezf .zffsinput').length;
        for (var i = 1; i <= number-1; i++){
            cksshj=cksshj+ovpraseFloat($("#djjess"+i).val());
        }
        return cksshj.toFixed(2);
    }
    //common end
</script>
<script type="text/javascript">
    //移动支付
    var payingOrFailed = null;  //true支付中或支付失败
    function CheckPayOK(settInfo) {
        //&&需要支付
        var needPay = '@(needPay)' == 'True';
        if (!needPay) {
            return true;
        }
        var payMoney = 0;
        var alipayMoney = 0;
        var wechatMoney = 0;
        if (settInfo.zfje1 > 0) {
            if (settInfo.zffs1 == '10') {
                alipayMoney = settInfo.zfje1;
            }
            else if (settInfo.zffs1 == '11') {
                wechatMoney = settInfo.zfje1;
            }
        }
        if (settInfo.zfje2 > 0) {
            if (settInfo.zffs2 == '10') {
                alipayMoney = settInfo.zfje2;
            }
            else if (settInfo.zffs2 == '11') {
                wechatMoney = settInfo.zfje2;
            }
        }
        if (alipayMoney > 0 && wechatMoney > 0) {
            $.modalAlert('支付方式选择错误', 'error');
            return false;    //支付方式选择错误
        }
        payMoney = alipayMoney + wechatMoney;
        if (payMoney <= 0) {
            //不需要移动支付
            payingOrFailed = null;
            return true;
        }
        if (payMoney > 0 && !!settInfo.zffs1 && !!settInfo.zffs2) {
            $.modalAlert('移动支付<br/>不支持选择多种支付方式', 'error');
            return false;    //支付方式选择错误
        }
        if (payMoney > 0 && settInfo.zhaoling != 0) {
            $.modalAlert('移动支付不能有找零', 'error');
            return false;
        }
        if ((payingOrFailed === null || payingOrFailed === true) && needPay && payMoney > 0) {
            payMoney = ovpraseFloat(payMoney).toFixed(2);
            var out_trade_no = (new Date()).getTime().toString();   //是否有问题？
            ToPay(out_trade_no, '出院结算', payMoney);
            payingOrFailed = true;
        }
        return !(payingOrFailed === true); //支付中 返回true，否则返回false
    }
    //发起支付
    function ToPay(out_trade_no, subject, total_amount) {
        var title = '付款码支付-' + (subject.length <= 15 ? subject : subject.substring(0, 12) + "...");
        var url = "/PayManage/MicroPay/MicroPay";
        url += '?out_trade_no=' + out_trade_no;
        url += '&subject=' + subject;
        url += '&total_amount=' + total_amount;
        $.modalOpen({
            id: "ToPay",
            title: title,
            url: url,
            width: "400px",
            height: "210px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick(function (data) {
                    //pay success callback
                    PaySuccessHandle(data);
                });
            }
        });
    }
    //支付成功-继续提交结算
    var outTradeNo;
    function PaySuccessHandle(data) {
        payingOrFailed = false;

        outTradeNo = data.outTradeNo;
        //移动支付方式纠正
        if (data.payType == 1 && $('#zffs1').val() == '11') {
            $('#zffs1').val("10").trigger('change');
        }
        if (data.payType == 2 && $('#zffs1').val() == '10') {
            $('#zffs1').val("11").trigger('change');
        }
        AcceptClick(theAcceptClickCallBack);
    }

    //预交金充值通道
    function InpAccountDeposit() {
        var czje = (ovpraseFloat(xjzfys) - ovpraseFloat(yjjye)).toFixed(2);
        $.modalOpen({
            id: "YjjDeposit",
            title: "预交金补充值",
            url: "/HospitalizationManage/DischargeSettle/HosAccountDeposit?je="+czje,
            width: "350px",
            height: "240px",
            callBack: function (iframeId) {
                var xz = '@((int)EnumXTZHXZ.ZYYJKZH)';
                top.frames[iframeId].SubmitAccountDeposit(patid, xz); //在弹出窗口事件
                $.reload();
            }
        });
    }

    function yjjRefresh() {
        //预交金处理
        if (!!yjjye && yjjye >= xjzfys && $("#zffs1 option:selected").val() == "3") {
            //$("#td_accountcharge").hide();
            if ($('#ckyjjzfyeqt').is(':checked')) {
                $('#zfje1').val(ovpraseFloat(yjjye).toFixed(2));
            }

            hjsskZhaolingCal();

        }
        else if (!!yjjye && yjjye < xjzfys && $("#zffs1 option:selected").val() == "3") {
            //$("#yjjczje").html(ovpraseFloat(xjzfys - yjjye).toFixed(2));
            //$("#td_accountcharge").show();
            hjsskZhaolingCal();
        }
    }
    function sswrjeCz()
    {
        if(SettPayBalance==="True")
        {
            var lastVal=xjzfys+"";
            lastVal =lastVal.substring(lastVal.length-1);
            if(lastVal==5)
                xjzfys=xjzfys-0.01;
            xjzfys=ovpraseFloat(xjzfys).toFixed(1);
        }
        return xjzfys;
    }
    //预交金支付
    function yjjReset() {
        xjzfys=sswrjeCz();
        if (ovpraseFloat(yjjye) > xjzfys) {
            $("#dv_yjjtye").show();
            $("#yeqtje").html(ovpraseFloat(yjjye - xjzfys).toFixed(2));
            $('#yjjzfje').html(ovpraseFloat(xjzfys).toFixed(2));
        }
        else {
            $('#yjjzfje').html(ovpraseFloat(yjjye).toFixed(2));
            $("#dv_yjjtye").hide();
        }
        if ('@refundyjj' == "1" && !ztjs) {
            $('#ckyjjzfyeqt').attr("checked", "checked");//.attr("disabled", "disabled");
            yjjyetq();
        }
        hjsskZhaolingCalNew();
    }
    //输入框控制
    function inputnum(obj, val) {
        obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
        obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
        obj.value = obj.value.replace(/\.{2,}/g, ""); //只保留第一个, 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
    }
    ///////////多种支付方式////////////////
    function clearnum(num) {
        if(!num)
            num="";
        $('#djjess'+num).select();
    }

    $('#tablezf .plusToggleCircle').click(function (){
        debugger;
        var isAdd=verifyZfje();
        if(isAdd==false)
        {
            $.modalAlert("当前窗口实收合计大于等于待缴金额，不可添加新支付方式", 'error');
            return;
        }
        var vcn = 0;
        $.each(top.clients.SysForCashPayList, function (key, value) {
            if (value.xjzffs != '3') {
                vcn ++;
            }
        });
        var number = $('#tablezf .zffsinput').length;
        if (number >= vcn) {
            return;
        }
        var $newTr= $('<tr><th class="formTitle" style="color:red;"><i class="fa fa-minus minusToggleCircle" aria-hidden="true"  name="idjjess' + number + '" style="width:30px;margin-left: 10px; color: #6ff3ad; font-size: large;"></i>窗口实收： </th><td class="formValue" style="font-size:large" colspan="2"> <input type="text" id="djjess' + number + '" name="djjess' + number + '" class="form-control required zffsinput" autocomplete="off" onkeyup="setzfje(' + number + ')" onfocus="clearnum(' + number + ')" onchange="verifyZffs('+number+')" style="width:90%" value="0.00" oninput="inputnum(this)" /></td><th class="formTitle">支付方式：</th> <td class="formValue" colspan="2"><select id="djjesszffs' + number + '" class="form-control  form-an" style="width:90%"><option value="">==请选择==</option></select></td></tr>');

        $newTr.appendTo($(this).closest('table'));
        binddzffsFloatingSelector(number);
        var djje= ovpraseFloat($("#djje").html()) ;
        var hjssk= ovpraseFloat($('#hjssk').html());
        var yjjzf=ovpraseFloat($("#yjjzfje").html());
        $("#djjess"+number).val(ovpraseFloat(djje+yjjzf-hjssk).toFixed(2));
        setzfje();
    });
    //重置窗口支付金额
    function czzfje()
    {
        $("#djjess").val(ovpraseFloat(0).toFixed(2));
        var number = $('#tablezf .zffsinput').length;
        for (var i = 1; i <= number-1; i++) {
            $("#djjess"+i).val(ovpraseFloat(0).toFixed(2));
        }

    }

    //是否可添加新支付方式
    function verifyZfje(num)
    {
        var djje= ovpraseFloat($("#djje").html())+ ovpraseFloat($("#yjjzfje").html());
        var hjssk= ovpraseFloat($('#hjssk').html());
        if(hjssk>=djje)
        {
            return false;
        }
        return true;
    }
    //删除icon
    $('#tablezf').on('click', '.minusToggleCircle', function (e) {
        debugger;
        var number = $('#tablezf .zffsinput').length;

        var removeTr=$(this).attr('name');
        var lastTr ="i"+$('#tablezf .zffsinput')[number-1].id;
        if(removeTr!=lastTr)
        {
            $.modalAlert('仅支持按最后一种支付方式开始删除', 'error');
            return;
        }
        $(this).closest('tr').remove();
        hjsskZhaolingCalNew();
    })
    //计算输入金额
    function setzfje(){
        hjsskZhaolingCalNew();
    }
    //change
    function verifyZffs(num){
        if ($("#djjesszffs"+num+" option:selected").val() == "" && ovpraseFloat($("#djjess"+num).val()) != 0) {
            $.modalAlert('请选择支付方式', 'error');
        }
    }
    function binddzffsFloatingSelector(num)
    {
        var zfdata = getzfArrayData();
        zfdata.pop();

        $("#djjesszffs"+num).newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                $.each(top.clients.SysForCashPayList, function (key, value) {
                    if (value.xjzffs == '3') {
                        return; //不显示该支付方式
                    }
                    var hasSelected = false;
                    for (var i = 0; i < zfdata.length; i ++) {
                        if (value.xjzffs == zfdata[i].zffsmc) {
                            hasSelected = true;
                            break;
                        }
                    }
                    if (!hasSelected) {
                        $('#djjesszffs'+num).append('<option value="' + value.xjzffs + '" selected >' + value.xjzffsmc + '</option>');
                    }
                    else {
                        $('#djjesszffs'+num).append('<option value="' + value.xjzffs + '">' + value.xjzffsmc + '</option>');
                    }
                });
                return resultObjArr;
            }
        });
    }
    function getzfArrayData()
    {
        var PatZfList = [];
        var PatZfObj = {
            zfje:  $('#djjess').val(),
            zffsmc:  $('#djjesszffs option:selected').val()
        }
        PatZfList.push(PatZfObj);
        var number = $('#tablezf .zffsinput').length;
        for (var i = 1; i <= number-1; i++) {
            PatZfObj = {
                zfje:ovpraseFloat($("#djjess" + i).val()).toFixed(2),
                zffsmc:$("#djjesszffs"+i+" option:selected").val()
            }
            PatZfList.push(PatZfObj);
        }
        return PatZfList;
    }
</script>

